package cn.service.marketingService.MarketingServiceImpl;

import cn.service.marketingService.HotMarketingService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.marketingEntity.Hotmarketing;
import entity.marketingEntity.NewMarketingCondition;
import entity.Result;
import mapper.marketingMapper.HotmarketingMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 朱颢阳
 * @description
 * @time 2024/8/30 10:29
 */
@Service
public class HotMarketingServiceImpl implements HotMarketingService {
    @Resource
    HotmarketingMapper mapper;

    @Override
    public Result getHotMarking(NewMarketingCondition condition) {
        PageHelper.startPage(condition.getCurrentPage(),condition.getPageSize());
        Page<Hotmarketing> page= (Page<Hotmarketing>) mapper.selectAll(condition);
        System.out.println(page.getTotal());
        return Result.success((int)page.getTotal(),page.getResult());
    }

    @Override
    public Result updateHotMarkingRecommend(Integer id, Integer recommend) {
        if (mapper.updateHotMarkingRecommend(id,recommend)>0){
            return Result.success("推荐状态更新成功");
        }else{
            return Result.failed(500,"推荐状态更新失败！");
        }
    }

    @Override
    public Result updateHotMarkingSort(Integer id, Integer sort) {
        if (mapper.updateHotMarkingSort(id,sort)>0){
            return Result.success("排序更新成功");
        }else{
            return Result.failed(500,"排序更新失败！");
        }
    }

    @Override
    public Result addHotMarketing(List<String> list) {
        for (String s : list) {
            if(mapper.insert(new Hotmarketing(s))<1){
                return Result.failed(500,"新品推荐失败！");
            }
        }
        return Result.success("新品推荐成功");
    }

    @Override
    public Result deleteHotMarketing(Integer id) {
        if (mapper.deleteByPrimaryKey(id)>0){
            return Result.success("删除成功");
        }else{
            return Result.failed(500,"删除失败！");
        }
    }
}